﻿using System;
using WYJ.Log.LogWriters;

namespace WYJ.Log.LogServices
{
    public abstract class BaseLogger
    {
        public static LogLevel[] Levels  => (LogLevel[])typeof(LogLevel).GetEnumValues();

        public void Debug(string message)
        {
            Write(message, LogLevel.DEBUG);
        }

        public void Info(string message)
        {
            Write(message, LogLevel.INFO);
        }

        public void Warn(string message)
        {
            Write(message, LogLevel.WARN);
        }

        public void Error(string message)
        {
            Write(message, LogLevel.ERROR);
        }

        public void Fatal(string message)
        {
            Write(message, LogLevel.FATAL);
        }


        public void Resume(LogLevel logLevel)
        {
            GetLogger(logLevel)?.Resume();
        }

        public void Pause(LogLevel logLevel)
        {
            GetLogger(logLevel)?.Pause();
        }


        protected abstract ILogWriter? GetLogger(LogLevel logLevel);

        protected virtual string Formate(string message)
        {
            return message;
        }

        private void Write(string message, LogLevel logLevel)
        {
            GetLogger(logLevel)?.WriteAsync($"{logLevel}: {DateTime.Now} =>\r\n\t{Formate(message)}\r\n");
        }
    }
}